#Script used to Convert a spritesheet
#Into several sprite files
#Into their own directory
import os
import pygame

pygame.init()
src=None
while not src:
	try:src=pygame.image.load(input("input filename> "))
	except:pass

name=input("output directory> ")
try:os.mkdir(name)
except:pass
try:os.chdir(name)
except:pass

spr_size,pos,cur=[int(input("Sprite width> ")),int(input("Sprite height>"))],[0]*2,0
if spr_size[1]<0:spr_size[1]=spr_size[0]

while pos[1]<src.get_height():
	cur+=1
	export=pygame.Surface(spr_size,pygame.SRCALPHA)
	export.fill((255,0,255,1))
	export.blit(src,(0,0),pos+spr_size)
	pygame.image.save(export,"{:0>4}.png".format(cur))
	pos[0]+=spr_size[0]
	if pos[0]>=src.get_width():pos=[0,pos[1]+spr_size[1]]
